package com.file;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class Test_5 {
    public static void main(String[] args) {
        copy();
    }
    public static void copy(){
        FileOutputStream fileOutputStream=null;
        FileInputStream fileInputStream=null;
        String pathname="D:\\javacode\\javacode\\J2024_11_16\\gold.png";
        String copyname="D:\\javacode\\javacode\\J2024_11_16\\gold2.png";
        byte []buf=new byte[1024];//数组大小?
        int readlen=0;
        try {

            fileInputStream=new FileInputStream(pathname);
            fileOutputStream=new FileOutputStream(copyname);
            while((readlen=fileInputStream.read(buf))!=-1){
                fileOutputStream.write(buf,0,readlen);//输出一定要用这个方法
            }


        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            try {
                if(fileInputStream!=null) {
                    fileInputStream.close();
                }
                if(fileOutputStream!=null){
                    fileOutputStream.close();
                }
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
